package scenarios.gui.actions;

import scenarios.net.NetNodeModel;
import scenarios.net.TestNode;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: gvennet
 * Date: 21.02.2010
 * Time: 13:42:01
 */
public class NodesNetworks extends AbstractAction
{
	private ArrayList<TestNode> nodes;
	private NetNodeModel nodeModel;
	JToggleButton netButton;

	public NodesNetworks(ArrayList<TestNode> nodes, NetNodeModel nodeModel, JToggleButton netButton)
	{
		super("Включить сеть");
		this.nodeModel = nodeModel;
		this.nodes = nodes;
		this.netButton = netButton;
	}

	public void actionPerformed(ActionEvent e)
	{
		if (netButton.isSelected())
		{
			for (TestNode node : nodes)
			{
				node.startNetwork();
				nodeModel.update(node.getId(), node.getPort(), true);
			}
			netButton.setText("Выключить сеть");
		}
		else
		{
			for (TestNode node : nodes)
			{
				node.stopNetwork();
				nodeModel.update(node.getId(), node.getPort(), false);
			}
			netButton.setText("Включить сеть");
		}
	}
}

